var express = require('express');
var router = express.Router();
var { shopListModel } = require("../model/model")
/* GET home page. */
router.get('/', function (req, res, next) {
  res.render('index', { title: 'Express' });
});
router.get("/shoplist", async (req, res) => {
  let result = await shopListModel.find().populate("lid")

  res.send({
    code: 200,
    data: result
  })
})

router.put("/upshoplist", async (req, res) => {
  console.log(req.body);
  await shopListModel.updateOne({ _id: req.body._id }, req.body)
  res.send({
    code: 200,
  })
})
router.put('/upcheckall', async (req, res) => {
  await shopListModel.updateMany({}, { flag: req.body.flag })
  res.send({
    code: 200
  })
})
router.delete('/delshoplist', async (req, res) => {
  await shopListModel.deleteMany({ _id: { $in: req.query._id } })
  res.send({
    code: 200
  })
})
module.exports = router;
